package org.ihelpuoo.weboo.checkers;

import org.ihelpuoo.lang.StringUtils;
import org.ihelpuoo.weboo.DataChecker;
import org.ihelpuoo.weboo.bean.ParamBean;
import org.ihelpuoo.weboo.module.ActionContext;

public class CheckError
{
	private String	name;
	private String	message;
	private String	tip;

	public CheckError()
	{
		message = DataChecker.INVALID_VALUE;
	}

	public CheckError(String msg)
	{
		message = msg;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getMessage()
	{
		return message;
	}

	public void setMessage(String message)
	{
		this.message = message;
	}

	public String getTip()
	{
		return tip;
	}

	public void setTip(String tip)
	{
		this.tip = tip;
	}

	public CheckError formatByContext(ActionContext context, ParamBean param)
	{
		message = context.getMessage(message);
		if (!StringUtils.isBlank(name))
			message += " - ";
		name = context.getMessage(param.getAliasName());
		if (!StringUtils.isBlank(name))
			name += ": ";
		tip = context.getMessage(param.getComment());
		if (!StringUtils.isBlank(tip))
			tip = "\"" + tip + "\"";
		return this;
	}
}
